package com.cy;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.crypto.IllegalBlockSizeException;
import java.lang.ref.ReferenceQueue;
import java.util.Optional;

import static com.cy.DemoUtil.desDecript;

/**
 * @author suwenguang
 * @since 2022-09-29 00:57
 */
@RestController
public class Controller {

    @RequestMapping("/aes")
    public String ase(@RequestBody Req req) throws Exception {
        String key = Optional.ofNullable(req)
                .map(Req::getKey)
                .orElseThrow(IllegalArgumentException::new);
        String text = Optional.ofNullable(req)
                .map(Req::getText)
                .orElseThrow(IllegalArgumentException::new);

        return desDecript(text, key);
    }
}
